//
//  LLMallBrandCollectionViewCell.m
//  lrlzapp
//
//  Created by dl on 16/3/1.
//  Copyright © 2016年 lrlz. All rights reserved.
//

#import "LLMallBrandCollectionViewCell.h"
#import "LLMenuItemDataViewModel.h"

@interface LLMallBrandCollectionViewCell ()
@property(nonatomic, strong) LLMenuItemDataViewModel *viewModel;
@property(nonatomic, strong) CALayer *topLine;
@property(nonatomic, strong) CALayer *rightLine;
@property(nonatomic, strong) LLUIImageView *imageView;
@property(nonatomic, strong) UILabel *titleLabel;
@end

@implementation LLMallBrandCollectionViewCell

- (instancetype)initWithFrame:(CGRect)frame {
    self = [super initWithFrame:frame];
    if (self) {
        self.backgroundColor = [UIColor whiteColor];

        self.topLine = [CALayer layer];
        _topLine.frame = CGRectMake(0, 0, self.ll_width, SUIT_LINE_WIDTH);
        _topLine.backgroundColor = UI_COLOR_LINE_GREY.CGColor;
        [self.layer addSublayer:_topLine];

        self.rightLine = [CALayer layer];
        _rightLine.frame = CGRectMake(self.ll_width - SUIT_LINE_WIDTH, 0, SUIT_LINE_WIDTH, self.ll_height);
        _rightLine.backgroundColor = UI_COLOR_LINE_GREY.CGColor;
        [self.layer addSublayer:_rightLine];

        self.imageView = [[LLUIImageView alloc] initWithFrame:CGRectMake(
                (self.ll_width - SUIT_W_320(73.5)) / 2.f,
                SUIT_LINE_WIDTH,
                SUIT_W_320(73.5) - SUIT_LINE_WIDTH,
                self.ll_height - SUIT_LINE_WIDTH
        )];
        _imageView.backgroundColor = [UIColor whiteColor];
        [self addSubview:_imageView];

        self.titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(0,
                (_imageView.ll_height - SUIT_H(20)) / 2.f,
                _imageView.ll_width,
                SUIT_H(20))];
        _titleLabel.text = @"更多品牌";
        _titleLabel.font = SUIT_FONT_320(14);
        _titleLabel.textColor = UI_COLOR_FONT_BLACK;
        _titleLabel.textAlignment = NSTextAlignmentCenter;
        [_imageView addSubview:_titleLabel];
    }
    return self;
}

- (void)bindViewModel:(id)viewModel {
    self.viewModel = viewModel;

    RAC(self.topLine, hidden) = [[RACObserve(self.viewModel, showTopLine)
            not]
            takeUntil:self.rac_prepareForReuseSignal];
    RAC(self.rightLine, hidden) = [[RACObserve(self.viewModel, showRightLine)
            not]
            takeUntil:self.rac_prepareForReuseSignal];
    RAC(self.titleLabel, hidden) = [[RACObserve(self.viewModel, isRemoteData)
            not]
            takeUntil:self.rac_prepareForReuseSignal];

    @weakify(self)
    [[[RACObserve(self.viewModel, imageUrl)
            takeUntil:self.rac_prepareForReuseSignal]
            distinctUntilChanged]
            subscribeNext:^(NSString *imageUrl) {
                @strongify(self)
                [self.imageView setImageUrlStr:imageUrl];
            }];
}

@end
